package com.ruoyi.job.util;


import java.io.IOException;
import java.net.URL;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.xfire.client.Client;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * 身份证联网核查服务
 */
@Component
public class IdCardNetVerify {

    private static final Logger logger = Logger.getLogger(IdCardNetVerify.class);

    // 联网核查接口地址
    private static String verifyUrl = "http://32.172.33.13:80/lsyd-service/idCardService.ws?wsdl";


    public static String verify(String idCard, String name) {
        Client client;
        try {
            client = new Client(new URL(verifyUrl));
            client.setTimeout(240000);
            Object[] responseData = client.invoke("verify", new Object[] { idCard, name });
            return (String) responseData[0];
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return null;
    }

    public static void main(String[] args) {
        String jsonStr = IdCardNetVerify.verify("34100319931202081X", "丁凯");
        if (StringUtils.isNotEmpty(jsonStr)) {
            JSONObject json = JSON.parseObject(jsonStr);
            String code = json.getString("code");
            if ("00".equals(code)) {
                String idCardNo = json.getString("idCard");
                String name = json.getString("name");
                String res = json.getString("msg");
                String photo = json.getString("photo");
                System.out.println("返回状态码：" + code);
                System.out.println("身份证号码:" + idCardNo);
                System.out.println("用户姓名:" + name);
                System.out.println("提示信息:" + res);
                System.out.println("头像:" + photo);

                Base64ImageHelper.generateImage(photo, "D://", "34100319931202081X.jpg");
            } else {
                System.out.println(json.getString("msg"));
            }
        }
    }

}

